package website.sgg.type1;

import cn.hutool.core.thread.ThreadUtil;

/**
 * @Author: 582895699@qq.com
 * @Desctription:
 * @Date: Created in 2023/1/9 21:40
 */
public class SingletonTest1 {
    public static void main(String[] args) {
        ThreadUtil.concurrencyTest(10, () -> {
            Singleton instance = Singleton.getInstance();
            System.out.println(instance.hashCode());
        });
    }

}

class Singleton {
    private Singleton() {
    }

    private static Singleton instance;

    public static Singleton getInstance() {
        if (instance == null) {
            synchronized (Singleton.class) {
                instance = new Singleton();
            }
        }
        return instance;
    }
}